package com.hzvdvmc.autosale.socket;

import android.text.TextUtils;
import android.widget.TextView;

import com.hzvdvmc.autosale.constant.SpKey;
import com.hzvdvmc.autosale.util.SPUtils;

/**
 * Created by william on 2017/11/14.
 */

public class HttpConstants {
    //debug
//    public static final String SOCKET_SERVER_IP_DEFAULT = "120.27.217.224";
//    public static final String HTTP_IP_DEFALUT = "120.27.217.224";
//    public static final String SOCKET_SERVER_PORT_DEFAULT = "8881";
//    public static final String HTTP_PORT_DEFAULT = "8088";

    //正式的
    public static final String SOCKET_SERVER_IP_DEFAULT = "106.14.190.9";
    public static final String SOCKET_SERVER_PORT_DEFAULT = "9999";
    public static final String HTTP_IP_DEFALUT = "106.14.190.9";
    public static final String HTTP_PORT_DEFAULT = "8088";

    public static String getHost(){
        String host = "http://" + getHttpIP();
        if (!TextUtils.isEmpty(getHttpPort())){
            if (getHttpPort().startsWith(":")){
                host = host + getHttpPort();
            }else {
                host = host + ":" + getHttpPort();
            }

        }
        return host;
    }

    public static String getScoketIP() {
        String ip = SPUtils.getInstance().getString(SpKey.SOCKET_SERVER_IP);
        if (TextUtils.isEmpty(ip)){
            return SOCKET_SERVER_IP_DEFAULT;
        }
        return ip;
    }

    public static void setSocketIP(String ip){
        SPUtils.getInstance().put(SpKey.SOCKET_SERVER_IP,ip);
    }

    public static String getSocketPort() {
        String port = SPUtils.getInstance().getString(SpKey.SOCKET_SERVER_PORT);
        if (TextUtils.isEmpty(port)){
            return SOCKET_SERVER_PORT_DEFAULT;
        }
        return port;
    }

    public static void setSocketPort(String port){
        SPUtils.getInstance().put(SpKey.SOCKET_SERVER_PORT,port);
    }


    public static String getHttpIP() {
        String ip = SPUtils.getInstance().getString(SpKey.HTTP_IP);
        if (TextUtils.isEmpty(ip)){
            return HTTP_IP_DEFALUT;
        }
        return ip;
    }

    public static void setHttpIP(String ip){
        SPUtils.getInstance().put(SpKey.HTTP_IP,ip);
    }

    public static String getHttpPort() {
        String port = SPUtils.getInstance().getString(SpKey.HTTP_PORT);
        if (TextUtils.isEmpty(port)){
            return HTTP_PORT_DEFAULT;
        }
        return port;
    }

    public static void setHttpPort(String port){
        SPUtils.getInstance().put(SpKey.HTTP_PORT,port);
    }



    /**
     * 获取商品列表
     */
    public static String getShopList() {
        return HttpConstants.getHost() + "/api/Android/GetProductByMachine";
    }

    public static String getQRCodeValue() {
        return HttpConstants.getHost() + "/api/Android/RequestPayUrl";
    }

    public static String getAdverRes() {
        return HttpConstants.getHost() + "/api/Android/GetAd";
    }


}
